import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

public class Inet
{
    public static void main (String[] args) throws UnknownHostException
    {
        //InetAddress, 没构造方法, 不可以new
        //实例化获取计算机本地地址的InetAddress对象
        Inet4Address localHost = (Inet4Address) Inet4Address.getLocalHost();
        InetAddress inetAddressLocal = InetAddress.getLocalHost();
        //获取电脑IP、返回计算机地址、返回计算机名
        System.out.println(localHost);
        System.out.println(inetAddressLocal.getHostAddress());
        System.out.println(inetAddressLocal.getHostName());
        System.out.println();
        
        //实例化根据域名获取计算机信息的InetAddress对象
        InetAddress inetAddressName = InetAddress.getByName("www.baidu.com");
        //返回IP地址
        System.out.println("www.baidu.com " + inetAddressName.getHostAddress());
        System.out.println();
        
//        //实例化根据IP获取域名的InetAddress对象
//        InetAddress inetAddressIP = InetAddress.getByName("14.215.177.38");
//        //返回域名
//        System.out.println(inetAddressIP.getHostName());
//        System.out.println();
        
        //InetSocketAddress, 可以new该对象
        //new InetSocketAddress对象
        InetSocketAddress inetSocketAddress = new InetSocketAddress("www.itbaizhan.com", 80);
        System.out.println("www.itbaizhan.com " + inetSocketAddress.getAddress().getHostAddress());
        
    }
}
